
<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/usuarios/consulta');?>">Usuário</a></li>
  <li class="active">Novo</li>
</ol>
			<fieldset>
			<legend>Cadastro Usuário</legend>
				<form id="form" class="form-horizontal" role="form" >
					<div class="form-group">
					<label for="inputEmail3" class="col-sm-2 control-label">Login</label>
					<div class="col-sm-2">
						<?php 
							$data = array('name'=> 'login','id'=> 'login','value'=> @$usuario->login,'placeholder'=> 'Login','class'=> 'form-control input-sm');
							echo form_input($data);
						?>
					</div>
					</div>
					<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">Nome Completo</label>
					<div class="col-sm-4">
						<?php 
							//$data = array('readonly'=>'readonly','name'=> 'nome','id'=> 'nome','value'=> @$usuario->nome_completo,'placeholder'=> 'Nome Completo','class'=> 'form-control input-sm');
							$data = array('name'=> 'nome','id'=> 'nome','value'=> @$usuario->nome_completo,'placeholder'=> 'Nome Completo','class'=> 'form-control input-sm');
							echo form_input($data);
						?>
					</div>
					</div>
					<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">Permissão</label>
					<div class="col-sm-2">
						<?php 
							echo form_dropdown('permissao',$permissao,'5','class="form-control input-sm" id="permissao"');
							
						?>
					</div>
					
					</div>
								
					<div class="form-group">
					<label for="inputPassword3" class="col-sm-2 control-label">Observação</label>
					<div class="col-sm-4">
						<?php 
							$data = array('name'=> 'observacao','id'=> 'observacao','placeholder'=> 'Observação','class'=> 'form-control input-sm', 'value'=> @$usuario->observacao,'rows'=>'3' );
							echo form_textarea($data);
						?>
					</div>
					</div>
					<div id="divproce">
					<?php
					echo form_fieldset('Atende quais processos?');
					?>

					<div class="form-group">
					<label for="" class="col-sm-2 control-label">Processo Administrativo</label>
					<div class="col-sm-4">
							<div class="make-switch switch-mini" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
									<input type="checkbox" name="processos[]" value="1" checked />
							</div>  
					</div>
					</div>
					<div class="form-group">
					<label for="" class="col-sm-2 control-label">Processo Judicial</label>
					<div class="col-sm-4">
							<div class="make-switch switch-mini" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
									<input type="checkbox" name="processos[]" value="2" checked class="form-control input-sm"/>
							</div>  
					</div>
					</div>
					<div class="form-group">
					<label for="" class="col-sm-2 control-label">Execução Fiscal</label>
					<div class="col-sm-4">
							<div class="make-switch switch-mini" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
									<input type="checkbox" name="processos[]" value="3" checked class="form-control input-sm"/>
							</div>  
					</div>
					</div>
					
					<?php
							echo form_fieldset_close(); 
					?>
					</div>
					<div class="form-group" id="divexcecao">
					<label for="" class="col-sm-2 control-label">Atende Processos exceção</label>
					<div class="col-sm-2">
						<?php 
							$excecao = array('0'=>'-- --','1'=>'IPPASA','2'=>'LICITAÇÃO','3'=>'PROCURADOR GERAL');
							echo form_dropdown('excecao',$excecao,'0','class="form-control  input-sm" id="excecao"');
						?>
					</div>
					<div class="col-sm-2 control-label" style="text-align:left;color:red;">
					<?php echo form_error('tipo_processo');?>	
					</div>	
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
						<?php 
							$data = array('name'=>'salvar','type' => 'submit','class' => 'btn btn-primary','content' =>'Salvar');
							echo form_button($data);
							//$data = array('name'=>'cancelar','type' => 'cancel','class' => 'btn btn-default','content' => 'Cancelar');
							//echo form_button($data);
							
						?>
							<a id="cancelar" href="<?php echo base_url('/index.php/usuarios/consulta');?>" class="btn btn-default"></span>Cancelar</a>
						</div>
					</div>

				</form>
				<div id="retorno1"></div>
			</fieldset>

		</div>



	<link href="<?php echo base_url('includes/css/bootstrap-switch.css') ?>" rel="stylesheet">
	<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css">
	<script src="<?php echo base_url('includes/js/bootstrap-switch.js')?>"></script>

	<link href="<?php echo base_url('includes/css/flat-ui-fonts.css') ?>" rel="stylesheet">
	<script language="javascript" type="text/javascript">
			$(document).ready(function(){//Equivalente ao window.onload porem mais rapido
				$("#login").focus();
				$("#divexcecao").hide();
				$("#divproce").hide();
				$("#form").validate({
					rules: {
						login: { 
							required: true, 
							remote:'<?php echo base_url('index.php/usuarios/validaUsuario');?>'
						},
						nome: "required"
					},
					messages: {
						login: { required: 'Preencha o campo', remote: ' Login já cadastrado!' },
						nome: "Campo requerido"
					},
					submitHandler: function(form){
					var dados = $('#form').serialize();
					$.ajax({
						type: "POST",
						url: "<?php echo base_url('index.php/usuarios/salvar'); ?>",
						data: dados,
						success: function( data )
						{
							$("html, body").animate({ scrollTop: $(document).height() }, "slow");
							if(data === 'OK'){
								
								$('#retorno1').html('<div class="alert alert-success" role="alert">CADASTRO REALIZADO COM SUCESSO</div>');
								$('#login').val('');
								$('#nome').val('');
								$('#observacao').val('');
								$('#excecao').val('');
								setTimeout(function() {
									$('#retorno1').html('');
									
									//window.location.href = "<?php echo base_url('index.php/usuarios/consulta'); ?>";
								}, 2000);
							}else{
								$('#retorno1').html(data);
							}
						},
						statusCode: {
							404: function() {
								alertify.error("Pagina nao encontrada");
							}
						}
					});
					return false;
				}
				});
				$( "#login" ).autocomplete({
					source: "<?php echo base_url('index.php/usuarios/consultaUserAD');?>",
					minLength: 2,
					select: function( event, ui ) {
						$("#nome").val(ui.item.fullname);
					}
				});
				$("#permissao").change(function(){
				 if($(this).val()=="3"){
						$("#divexcecao").show();
						$("#divproce").show();
				 } else {
						$("#divexcecao").hide();
						$("#divproce").hide();
				 }
			})
			});
	</script>	
	</body>
</html>